﻿Imports DTO
Imports System.Data.SqlClient

Public Class CTinhTrangChiTietPhieuMuonDAO
    Public Function LayDanhSachTinhTrangChiTietPhieuMuon() As List(Of CTinhTrangChiTietPhieuMuonDTO)
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As New SqlCommand("usp_LayDanhSachTinhTrangChiTietPhieuMuon", cn)
            cm.CommandType = CommandType.StoredProcedure
            Dim listttctpm As New List(Of CTinhTrangChiTietPhieuMuonDTO)()
            Using reader As IDataReader = cm.ExecuteReader(CommandBehavior.CloseConnection)
                While reader.Read()
                    listttctpm.Add(New CTinhTrangChiTietPhieuMuonDTO(reader))
                End While
            End Using
            Return listttctpm
        End Using
    End Function

    Public Function ThemTinhTrangChiTietPhieuMuon(ByVal tentinhtrangchitietphieumuon As String) As Integer
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As New SqlCommand("usp_ThemTinhTrangChiTietPhieuMuon", cn)
            cm.CommandType = CommandType.StoredProcedure
            Dim para As New SqlParameter("@tentinhtrangchitietphieumuon", tentinhtrangchitietphieumuon)
            cm.Parameters.Add(para)
            Dim parakq As New SqlParameter("@kt", 0)
            parakq.Direction = ParameterDirection.Output
            cm.Parameters.Add(parakq)
            cm.ExecuteNonQuery()
            Dim kq As Integer = Integer.Parse(cm.Parameters("@kt").Value.ToString())
            cn.Close()
            Return kq
        End Using
    End Function


    Public Function CapNhatTinhTrangChiTietPhieuMuon(ByVal tinhtrangchitietphieumuon As CTinhTrangChiTietPhieuMuonDTO) As Integer
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As New SqlCommand("usp_CapNhatTinhTrangChiTietPhieuMuon", cn)
            cm.CommandType = CommandType.StoredProcedure
            Dim para As New SqlParameter("@matinhtrangchitietphieumuon", tinhtrangchitietphieumuon.Ma)
            cm.Parameters.Add(para)
            para = New SqlParameter("@tentinhtrangchitietphieumuon", tinhtrangchitietphieumuon.Ten)
            cm.Parameters.Add(para)
            Dim parakt As New SqlParameter("@kt", 0)
            parakt.Direction = ParameterDirection.Output
            cm.Parameters.Add(parakt)

            cm.ExecuteNonQuery()
            Dim kq As Integer = Integer.Parse(cm.Parameters("@kt").Value.ToString())
            cn.Close()
            Return kq
        End Using
    End Function

End Class
